﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Bitirme.DAL.Entities;
using Bitirme.DAL.Enum;
using Bitirme.DAL.Data_Access;

namespace Bitirme.Controllers
{
    public class SkillHandler
    {
        int id;
        Capability capability;
        static List<Capability> capabilities = null;
        public SkillHandler() {
            GetCapabilityList();
        }

        public int GetCapabilityList() {
            capabilities = CapabilityCollection.GetAllCapabilities();
            return capabilities.Count;
        }

        public Dictionary<int, int> InsertCapability(Dictionary<string, int> capabilityMap)
        {
            List<int> capabilityIDList = new List<int>();
            Dictionary<int, int> capabilityIDMap = new Dictionary<int, int>();
            foreach (KeyValuePair<string, int> caps in capabilityMap)
            {
                capability = new Capability();
                capability.Name = caps.Key;
                bool isFound = false;
                foreach (Capability item in capabilities)
                {
                    if (item.Name == caps.Key)
                    {
                        id = item.ID;
                        capabilityIDMap.Add(id, caps.Value);
                        //capabilityIDList.Add(id);
                        isFound = true;
                        break;
                    }
                }
                if (!isFound)
                {
                    id = CapabilityCollection.InsertCapability(capability);
                    capabilityIDMap.Add(id, caps.Value);
                    //capabilityIDList.Add(id);
                }
            }

            return capabilityIDMap;
        }
    }
}